<?php

namespace App\Http\Middleware;

use Illuminate\Support\Facades\Lang;
use Closure;

class Translation
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // 将翻译共享到所有视图, 除 404 类错误视图
        $translations = [];
        $translations['auth'] = Lang::get('auth');
        $translations['pagination'] = Lang::get('pagination');
        $translations['passwords'] = Lang::get('passwords');
        $translations['validation'] = Lang::get('validation');
        $translations['t'] = Lang::get('t');

        view()->share('translations', $translations);

        return $next($request);
    }
}
